<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use DB;

class IndexController extends Controller
{
    public function __construct()
    {
    }

    public function index()
    {
        return view('index');
    }

    //get Slide
    public function getSlide()
    {
        $slide = DB::table('matter')->where('recommend', 1)->get();
        return $slide;
    }

    //Index matter list
    public function getMatter()
    {
        $matter = DB::table('matter')->where('status', 1)->get();
        return $matter;
    }

    public function getCate()
    {
        $cate = DB::table('category')->get();
        //TODO
        return $cate;
    }

    //Module matter list
    public function getModuleMatter(Request $request)
    {
        $mid = $request->input('mid', 0);
        $cate = DB::table('category')->where('module_id', $mid)->get();
        foreach($cate as $value) {
            $cates[] = $value->id;
        }
        $matter = DB::table('matter')->whereIn('cid', $cid)->get();
        return $matter;
    }
}
